package com.faker.dba.controller;

import com.faker.dba.filter.MobileAuthFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;

@RestController
@ApiIgnore
public class Swagger2HtmlController {
    /**
     * 日志对象
     */
    protected final Logger logger = LoggerFactory.getLogger(this.getClass());

    /**
     * 映射跳转页面
     *
     * @return
     */
    @GetMapping("/")
    public ModelAndView index(HttpServletRequest request) {
        //获取当前用户
        String __token = request.getHeader("__token");
        String __userId = request.getHeader("__userId");
        if (null != __userId) {
            // 查看最近登录验证的次数
            String token = MobileAuthFilter.userTokenMap.get(__userId);
            if (null != token && token.equals(__token)) {
                return new ModelAndView("redirect:/table.html");
            }
        }
        ModelAndView mav = new ModelAndView("redirect:/login.html"); // 绝对路径OK
        return mav;
    }
}
